package cn.hnh.service.impl;

import cn.hnh.constrant.RedisKeys;
import cn.hnh.constrant.ResultInfo;
import cn.hnh.mapper.*;
import cn.hnh.pojo.User;
import cn.hnh.service.SlideBarService;
import cn.hnh.utils.RedisUtils;
import cn.hnh.vo.Result;
import cn.hnh.vo.SlideBarVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author HuangNianHong
 * @Time 2021/1/5
 */
@Service
public class SlideBarServiceImpl implements SlideBarService {
    @Autowired
    private ArticleMapper articleMapper;
    @Autowired
    private CategoriesMapper categoriesMapper;
    @Autowired
    private TagsMapper tagsMapper;
    @Autowired
    private FriendsMapper friendsMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Override
    public Result<SlideBarVo> getSildeBarVo() {
        SlideBarVo slideBarVo = new SlideBarVo();
        User user = userMapper.getSlideBarUserById(1);
        if(user!=null){
            slideBarVo.setName(user.getName());
            slideBarVo.setImgurl(user.getImgurl());
            slideBarVo.setDescription(user.getDescription());
            slideBarVo.setArticleCount(articleMapper.getArticleCount());
            slideBarVo.setCategoriesCount(categoriesMapper.getCategoriesCount());
            slideBarVo.setTagsCount(tagsMapper.getTagsCount());
            slideBarVo.setFriends(friendsMapper.getFriendsInfo());
            slideBarVo.setPV((Integer) redisUtils.get(RedisKeys.WEBSITE_VIEW_COUNT));
            return new Result<>(ResultInfo.SUCCESS_CODE,ResultInfo.SUCCESS_MESSAGE,slideBarVo);
        }
        return new Result<>(ResultInfo.NOTFOUND_CODE,ResultInfo.NOTFOUND_MESSAGE);
    }
}
